using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;

namespace SensorVisual
{
    /// <summary>
    /// Esta clase implementa el atributo Desplazamiento que se recibe
    /// en los eventos del sensor.
    /// </summary>
    public class Movimiento
    {
        public float pan;
        public float tilt;
        public float rot;
        public float avance;

        [StructLayout(LayoutKind.Sequential)]
        internal struct Movimiento_cpp
        {
            public float pan;
            public float tilt;
            public float rot;
            public float avance;
        }

        public static Movimiento Nulo
        {
            get { return new Movimiento(0, 0, 0, 0); }
        }

        public Movimiento()
        {
            this.pan = 0;
            this.tilt = 0;
            this.rot = 0;
            this.avance = 0;
        }

        public unsafe Movimiento(IntPtr mov)
        {
            this.pan = ((Movimiento_cpp*)mov)->pan;
            this.tilt = ((Movimiento_cpp*)mov)->tilt;
            this.rot = ((Movimiento_cpp*)mov)->rot;
            this.avance = ((Movimiento_cpp*)mov)->avance;
        }

        public Movimiento(float pan, float tilt, float rot, float avance)
        {
            this.pan = pan;
            this.tilt = tilt;
            this.rot = rot;
            this.avance = avance;
        }

        internal Movimiento_cpp ToNative()
        {
            Movimiento_cpp m;
            m.pan = this.pan;
            m.tilt = this.tilt;
            m.rot = this.rot;
            m.avance = this.avance;

            return m;
        }

        public static Movimiento operator +(Movimiento d1, Movimiento d2)
        {
            return new Movimiento(
                d1.pan + d2.pan,
                d1.tilt + d2.tilt,
                d1.rot + d2.rot,
                d1.avance + d2.avance);
        }
    }
}
